//
//  AIVipYearView.m
//  Mia
//
//  Created by Vill on 2024/1/5.
//

#import "AIVipYearView.h"

@interface AIVipYearView ()

@property (nonatomic, strong) UILabel *leftLbl;  //左边文本
@property (nonatomic, strong) UILabel *moneyLbl; //金额
@property (nonatomic, strong) UILabel *perLbl;   //每月价格
@property (nonatomic, strong) UILabel *oriMoneyLbl; //原价
@property (nonatomic, strong) UIImageView *offsetImg;   //折扣
@property (nonatomic, strong) UILabel *offSetLbl;   //折扣比例

@end

@implementation AIVipYearView

- (instancetype)initWithFrame:(CGRect)frame{
    if(self == [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.leftLbl];
    [self.bgView addSubview:self.perLbl];
    [self.bgView addSubview:self.moneyLbl];
    [self.bgView addSubview:self.oriMoneyLbl];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self);
        make.top.mas_equalTo(self).mas_offset(PTW(12.5));
    }];
    [self.leftLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(PTW(50));
        make.bottom.mas_equalTo(self.bgView.mas_centerY).mas_offset(PTW(5));
    }];
    [self.perLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.leftLbl);
        make.top.mas_equalTo(self.leftLbl.mas_bottom);
    }];
    [self.moneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.bgView).mas_offset(-PTW(8));
        make.trailing.mas_equalTo(self.bgView).mas_offset(-PTW(45));
    }];
    [self.oriMoneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.moneyLbl);
        make.top.mas_equalTo(self.moneyLbl.mas_bottom).mas_offset(-PTW(5));
    }];
    [self addSubview:self.offsetImg];
    [self.offsetImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(PTW(83), PTW(25)));
    }];
    [self addSubview:self.offSetLbl];
    [self.offSetLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.offsetImg).mas_offset(PTW(5));
        make.centerY.mas_equalTo(self.offsetImg);
    }];
}

- (UIView *)bgView{
    if(!_bgView){
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor colorHex:@"#FFFFFF" alpha:0.3];
        _bgView.layer.cornerRadius = PTW(15);
        _bgView.layer.borderColor = UIColor.clearColor.CGColor;
        _bgView.layer.borderWidth = PTW(2);
    }
    return _bgView;
}

- (UILabel *)leftLbl{
    if(!_leftLbl){
        _leftLbl = [UILabel new];
        _leftLbl.text = @"1 Year";
        _leftLbl.font = [UIFont fontWithWeight:MTBold size:PTW(22)];
        _leftLbl.textColor = UIColor.whiteColor;
    }
    return _leftLbl;
}

- (UILabel *)perLbl{
    if(!_perLbl){
        _perLbl = [UILabel new];
        _perLbl.text = @"Only $5.83/Mo";
        _perLbl.font = [UIFont fontWithWeight:MTBold size:PTW(12)];
        _perLbl.textColor = [UIColor colorHex:@"#33FFC1"];
    }
    return _perLbl;
}

- (UILabel *)moneyLbl{
    if(!_moneyLbl){
        _moneyLbl = [UILabel new];
        _moneyLbl.text = @"$69.99";
        _moneyLbl.font = [UIFont fontWithWeight:Medium size:PTW(22)];
        _moneyLbl.textColor = UIColor.whiteColor;
    }
    return _moneyLbl;
}

-(UILabel *)oriMoneyLbl{
    if(!_oriMoneyLbl){
        _oriMoneyLbl = [UILabel new];
        _oriMoneyLbl.font = [UIFont fontWithWeight:Regular size:PTW(14)];
        _oriMoneyLbl.textColor = UIColor.whiteColor;
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"$239.99"];
        [str addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, str.length)];
        _oriMoneyLbl.attributedText = str;
    }
    return _oriMoneyLbl;
}

-(UIImageView *)offsetImg{
    if(!_offsetImg){
        _offsetImg = [UIImageView new];
        _offsetImg.image = KImaged(@"ai_vip_offSet");
    }
    return _offsetImg;
}

- (UILabel *)offSetLbl{
    if(!_offSetLbl){
        _offSetLbl = [UILabel new];
        _offSetLbl.text = @"66%OFF";
        _offSetLbl.font = [UIFont fontWithWeight:MTBold size:PTW(15)];
        _offSetLbl.textColor = UIColor.whiteColor;
    }
    return _offSetLbl;
}

@end
